//
//  TSZStatusTopView.swift
//  微博天下
//
//  Created by Tsz on 15/10/13.
//  Copyright © 2015年 Tsz. All rights reserved.

import UIKit

class TSZStatusTopView: UIView {
    /**微博模型数据
    */
    var data: TSZHomeMircoblogModel?{
        didSet {
            if let url = data?.user?.imageURL{
                iconView.sd_setImageWithURL(url)
            }
            nameLabel.text = data?.user?.name
            vipIconView.image = data?.user?.vipImage
            memberIconView.image = data?.user?.memberImage
            
            
            timeLabel.text = NSDate.sinaDate(data?.created_at ?? "")?.dateDesctiption
            sourceLabel.text = data?.source
        }
    }
    //MARK - 搭建界面都是在init中完成的  
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.clearColor()
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //搭建界面
    private func setupUI(){
        
        //添加顶部分割线
        let headerView = UIView()
        headerView.backgroundColor = UIColor(white: 0.8, alpha: 1.0)
        addSubview(headerView)
        headerView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size:  CGSize(width: UIScreen.mainScreen().bounds.width, height: 10))
        
        //头像
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(memberIconView)
        addSubview(vipIconView)
        //自动布局
        
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: headerView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 8, y: 8))
        
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: 12, y: 0))
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 12, y: 0))
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: timeLabel, size: nil, offset: CGPoint(x: 12, y: 0))
        memberIconView.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: nameLabel, size: nil, offset: CGPoint(x: 12, y: 0))
        vipIconView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 8))
    }
    
    //MARK -懒加载需要的控件
    /// 头像
    private lazy var iconView: UIImageView = UIImageView()
    //姓名
    private lazy var nameLabel: UILabel = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
    // 3. 时间标签
    private lazy var timeLabel: UILabel = UILabel(color: UIColor.orangeColor(), fontSize: 9)
    // 4. 来源标签
    private lazy var sourceLabel: UILabel = UILabel(color: UIColor.lightGrayColor(), fontSize: 9)
    //会员
    // 5. 会员图标
    private lazy var memberIconView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
    // 6. vip图标
    private lazy var vipIconView: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    
}
